package com.mz.ozy.widget.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.FirmOrderBean;

import java.util.List;

/**
 * Created by Administrator on 2018/11/21.
 */

public class GoodsInfoListDialog extends BaseDialog {

    private List<FirmOrderBean.ProductMapBean> mGoodsList;
    private TextView mTvCount;
    private ImageView mIvClose;
    private RecyclerView mRvContent;
    private MyAdapter mMyAdapter;

    public GoodsInfoListDialog(Activity mContext, List<FirmOrderBean.ProductMapBean> goodsList) {
        super(mContext, R.layout.dialog_goods_info_list, Gravity.BOTTOM, true, false);
        setMatchWidthDialog();
        mGoodsList = goodsList;
        init();
    }

    private void init() {
        mTvCount = getView(R.id.tv_count);
        mIvClose = getView(R.id.iv_close);
        mRvContent = getView(R.id.rv_content);

        mIvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getDialog().dismiss();
            }
        });
        mMyAdapter = new MyAdapter(null);
        mRvContent.setLayoutManager(new LinearLayoutManager(mContext));
        mRvContent.setAdapter(mMyAdapter);

        if (mGoodsList != null && !mGoodsList.isEmpty()) {

            int num = 0;
            for (FirmOrderBean.ProductMapBean goodsListBean : mGoodsList) {
                num += goodsListBean.getNum();
            }
            mTvCount.setText("共" + num + "件");
        }
        mMyAdapter.setNewData(mGoodsList);
    }


    class MyAdapter extends BaseQuickAdapter<FirmOrderBean.ProductMapBean, BaseViewHolder> {

        public MyAdapter(@Nullable List<FirmOrderBean.ProductMapBean> data) {
            super(R.layout.view_item_goods_info, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, FirmOrderBean.ProductMapBean item) {
            ImageView ivIcon = helper.getView(R.id.iv_icon);
            LinearLayout llChange = helper.getView(R.id.ll_change);
            TextView tvMoney = helper.getView(R.id.tv_money);
            TextView tvCoupon = helper.getView(R.id.tv_coupon);
            TextView tvChange = helper.getView(R.id.tv_change);
            ImageView ivType = helper.getView(R.id.ivType);

//            helper.setText(R.id.tv_title, item.getTradename())
//                    .setText(R.id.tv_info, "null".equals(item.getGoods_spec()) ? "" : item.getGoods_spec())
//                    .setText(R.id.tv_count, item.getNum() + "件");

//            if (!StringUtils.isZero(item.getPrice())) {
//                tvMoney.setText("¥" + StringUtils.formattingDecimal(item.getPrice(), 2));
//                tvMoney.setVisibility(View.VISIBLE);
//            } else {
//                tvMoney.setVisibility(View.GONE);
//            }

            Glide.with(mContext).load(item.getImg_zt()).into(ivIcon);
        }
    }
}
